import uuid

from rest_framework import serializers
from django.contrib.auth.hashers import make_password

from apps.menu.models import MenuType, Menu, MenuItem
from rsa import decripta_data


class MenuTypeSerializer(serializers.ModelSerializer):
    class Meta:
        model = MenuType
        fields = ['id', 'name', 'create_date', 'operator']

    def validate_name(self, value):
        if MenuType.objects.filter(name=value).exists():
            raise serializers.ValidationError("菜品类型已存在")
        return value


class MenuSerializer(serializers.ModelSerializer):
    class Meta:
        model = Menu
        fields = ['id', 'name', 'image', 'price', "desc", "create_time",
                  "type", "operator"]

    def validate_name(self, value):
        if Menu.objects.filter(name=value).exists():
            raise serializers.ValidationError("菜品已存在")
        return value


class MenuItemSerializer(serializers.ModelSerializer):
    class Meta:
        model = MenuItem
        fields = "__all__"
